//
//  PersonCenterInviteView.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/4/15.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "PersonCenterInviteView.h"

#import "MyInviteViewController.h"

@interface PersonCenterInviteView()<UIGestureRecognizerDelegate>

@property (nonatomic,strong) UIImageView *bgImgV;//背景图片

///会员       全部     直接   间接
@property (nonatomic,strong) UILabel *totalMemberLB;
@property (nonatomic,strong) UILabel *directlyMemberLB;
@property (nonatomic,strong) UILabel *indirectMemberLB;
///爱心大使    全部    直接   间接
@property (nonatomic,strong) UILabel *totalAmbassadorLB;
@property (nonatomic,strong) UILabel *directlyAmbassadorLB;
@property (nonatomic,strong) UILabel *indirectAmbassadorLB;
///工会       全部    直接   间接
@property (nonatomic,strong) UILabel *totalUnionLB;
@property (nonatomic,strong) UILabel *directlyUnionLB;
@property (nonatomic,strong) UILabel *indirectUnionLB;

@end

@interface PersonCenterInviteView()

@end

@implementation PersonCenterInviteView

-(id)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self initUI];
    }
    return self;
}

- (void)setInviteInfoDict:(NSDictionary *)inviteInfoDict{
    _inviteInfoDict = inviteInfoDict;
    NSInteger labor = [_inviteInfoDict[@"labor"] integerValue];
    NSInteger love = [_inviteInfoDict[@"love"] integerValue];
    NSInteger member = [_inviteInfoDict[@"member"] integerValue];
    NSInteger slabor = [_inviteInfoDict[@"slabor"] integerValue];
    NSInteger slove = [_inviteInfoDict[@"slove"] integerValue];
    NSInteger smember = [_inviteInfoDict[@"smember"] integerValue];
    NSInteger totalMember = member+smember;
    NSInteger totalLove = love+slove;
    NSInteger totalLabor = labor+slabor;
        
    self.totalMemberLB.text = [NSString stringWithFormat:@"会员 %ld",(long)totalMember];
    self.directlyMemberLB.text = [NSString stringWithFormat:@"直接 %ld",(long)member];
    self.indirectMemberLB.text = [NSString stringWithFormat:@"间接 %ld",(long)smember];
        
    self.totalAmbassadorLB.text = [NSString stringWithFormat:@"爱心大使 %ld",(long)totalLove];
    self.directlyAmbassadorLB.text = [NSString stringWithFormat:@"直接 %ld",(long)love];
    self.indirectAmbassadorLB.text = [NSString stringWithFormat:@"间接 %ld",(long)slove];
    
    self.totalUnionLB.text = [NSString stringWithFormat:@"工会 %ld",(long)totalLabor];
    self.directlyUnionLB.text = [NSString stringWithFormat:@"直接 %ld",(long)labor];
    self.indirectUnionLB.text = [NSString stringWithFormat:@"间接 %ld",(long)slabor];
}


-(void)initUI{
    [self addSubview:self.bgImgV];
    
    NSArray *totals = @[@"会员 0",@"爱心大使 0",@"工会 0"];
    NSArray *directlys = @[@"直接 0",@"直接 0",@"直接 0"];
    NSArray *indirects = @[@"间接 0",@"间接 0",@"间接 0"];
    
    float interval = (self.width-36)/3;
    for (int i = 0; i<3; i++) {
        UILabel *totalLB = [[UILabel alloc] initWithFrame:CGRectMake(18+i*interval, 20, interval, 22)];
        totalLB.textColor = MainBlackTextColor;
        totalLB.textAlignment = NSTextAlignmentCenter;
        totalLB.font = FontSetWithWeight(16, 0.3f);
        totalLB.text = totals[i];
        [self addSubview:totalLB];
        
        UILabel *directlyLB = [[UILabel alloc] initWithFrame:CGRectMake(totalLB.left, totalLB.bottom+20*Width_Scale, interval, 18)];
        directlyLB.textColor = MainBlackTextColor;
        directlyLB.textAlignment = NSTextAlignmentCenter;
        directlyLB.font = FontSet(14);
        directlyLB.text = directlys[i];
        directlyLB.tag = i;
        [self addSubview:directlyLB];
        
        directlyLB.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(directlyTapClick:)];
        tap.delegate = self;
        [directlyLB addGestureRecognizer:tap];
        
        UILabel *indirectLB = [[UILabel alloc] initWithFrame:CGRectMake(totalLB.left, directlyLB.bottom+16*Width_Scale, interval, 18)];
        indirectLB.textColor = MainBlackTextColor;
        indirectLB.textAlignment = NSTextAlignmentCenter;
        indirectLB.font = FontSet(14);
        indirectLB.text = indirects[i];
        indirectLB.tag = i;
        [self addSubview:indirectLB];
        
        indirectLB.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(indirectTapClick:)];
        tap1.delegate = self;
        [indirectLB addGestureRecognizer:tap1];
    
        if (i == 0) {
            self.totalMemberLB = totalLB;
            self.directlyMemberLB = directlyLB;
            self.indirectMemberLB = indirectLB;
        }else if (i == 1) {
            self.totalAmbassadorLB = totalLB;
            self.directlyAmbassadorLB = directlyLB;
            self.indirectAmbassadorLB = indirectLB;
        }else{
            self.totalUnionLB = totalLB;
            self.directlyUnionLB = directlyLB;
            self.indirectUnionLB = indirectLB;
        }
    }
}


#pragma mark - lazy
- (UIImageView *)bgImgV{
    if (!_bgImgV) {
        _bgImgV = [[UIImageView alloc] initWithFrame:self.bounds];
        _bgImgV.image = LoadImage(@"个人中心_邀请背景");
    }
    return _bgImgV;
}

#pragma mark - SEL
-(void)directlyTapClick:(UIGestureRecognizer *)ges{
    if ([UserInfomationManager shareManager].loginStatus == NO) {
        [Configuration loginClick];
        return;
    }
    UILabel *lb = (UILabel *)ges.view;
    NSInteger index = (NSInteger)lb.tag;
    MyInviteViewController *vc = [[MyInviteViewController alloc] init];
    vc.sourceType = index+1;
    vc.type = 1;
    [[Configuration getCurrentVC].navigationController pushViewController:vc animated:YES];
}
-(void)indirectTapClick:(UIGestureRecognizer *)ges{
    if ([UserInfomationManager shareManager].loginStatus == NO) {
        [Configuration loginClick];
        return;
    }
    UILabel *lb = (UILabel *)ges.view;
    NSInteger index = (NSInteger)lb.tag+1;
    MyInviteViewController *vc = [[MyInviteViewController alloc] init];
    vc.sourceType = index;
    vc.type = 2;
    [[Configuration getCurrentVC].navigationController pushViewController:vc animated:YES];
}


@end
